﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HFController;
using System.Web.SessionState;
using System.Web.Script.Serialization;
namespace HFWebApp.AjaxSource
{
    /// <summary>
    /// UserModify 的摘要说明
    /// </summary>
    public class UserModify : IHttpHandler ,IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            BagePages bp = new BagePages();
            context.Response.ContentType = "text/plain";
            string action = bp.GetAll("action");
            HFModel.ResultModel result = new HFModel.ResultModel();
            switch (action)
            { 
                case "1":
                    //当前用户修改密码
                    string NowPWD = bp.GetAll("NowPWD");
                    string PWD = bp.GetAll("PWD");
                    result = UserController.getController().doModifyUserPWD(NowPWD, PWD);
                    break;
                case "2":
                    string realname = bp.GetAll("realname");
                    string email = bp.GetAll("email");
                    string provinceid = bp.GetAll("provinceid");
                    string cityid = bp.GetAll("cityid");
                    string content = bp.GetAll("content");
                    result = UserController.getController().doModifyUserInfo(realname, email, provinceid, cityid, content);
                    break;
            }
            context.Response.Write(this.getJSONResult(result));
            context.Response.End();
        }

        protected string getJSONResult(HFModel.ResultModel result)
        {
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer(new SimpleTypeResolver());
            return jsSerializer.Serialize(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}